Skip to content

Custom Snippets Feature #2278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Jul 3, 2025
Merged

Custom Snippets Feature #2278

merged 61 commits into from
Jul 3, 2025

Conversation

devvaannsh
Copy link
Member

@devvaannsh devvaannsh commented May 29, 2025

Tracking issue: #2268
This PR brings the support of Custom Snippets feature to Phoenix.

Custom snippets let users define short abbreviations. When typed in the editor, these trigger a hint. Selecting the hint expands it into the corresponding template text.

This helps reduce development time by avoiding repetitive typing.

Visual References
https://github.com/user-attachments/assets/a0a8d4f4-42d1-4c94-b2e2-4529371284c3 <- checkout this video too.

Untitled.video.-.Made.with.Clipchamp.20.mp4

@devvaannsh
Copy link
Member Author

This are some more changes that are made (after rebase):
(Each point refers to a commit)

  1. Move all the files to parent 'Custom Snippets' directory and removed the 'src' directory.

  2. Added license to all the files of custom snippets

  3. There was a bug where custom snippets in code completion were showing up in creation order instead of relevance order. So if a user had snippets "clgi" and "clg", and "clgi" was created first, typing "clg" would show "clgi" at the top even though "clg" is an exact match. Fixed that by prioritizing exact matches over partial matches. Now when users type "clg", they'll see "clg" first (exact match) followed by "clgi" (partial match).

  4. Snippet description was not properly visible. Also increased the max-description length from 70 to 80 chars.
    Before
    custom-snippets
    After
    Screenshot 2025-06-07 024002

  5. When a multiline snippet was expanded into the editor (maybe inside a function or something) then the indentation was not being taken care of. Fixed that.

  6. Remove optional chaining as it is not supported and was causing the prod:release build to fail.

@abose abose requested a review from Copilot June 16, 2025 04:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a Custom Snippets feature to allow users to quickly expand short abbreviations into their corresponding code templates. Key changes include new CSS rules and Less imports to style custom snippet hints, new extension modules (such as snippetsState, snippetsList, snippetCodeHints, driver, and codeHintIntegration) for managing snippet state and editor integration, and a new UI panel for displaying and managing custom snippets.

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/styles/brackets_patterns_override.less Adds new styles for custom snippet code hints and snippet description display
src/styles/brackets.less Imports the custom snippets stylesheet
src/extensionsIntegrated/loader.js Loads the new Custom Snippets extension
src/extensionsIntegrated/CustomSnippets/*.js Introduces several new modules to manage snippet state, list, code hints, and integration with the editor
src/extensionsIntegrated/CustomSnippets/htmlContent/snippets-panel.html Provides the new UI panel for custom snippets

Copy link
Member

@abose abose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added review comments, but those are not breaking changes, except probably the possible event handler leaks.
So merging this change, the review comments can happen in another pull request.

Also pending is writing integration tests.

* @param {string} languageId - The language ID from Phoenix
* @returns {string} - The equivalent file extension for snippet matching
*/
function mapLanguageToExtension(languageId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use language = LanguageManager.getLanguageForPath(editor.document.file._path); or languageId = LanguageManager.getLanguageForPath(editor.document.file._path).getId(); to reliably get the language. this will honor users custom file type associations as well.

.split(",")
.map((ext) => ext.trim());

return supportedExtensions.some((ext) => ext === effectiveExtension);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these could be replaced with language check directly from languageId = LanguageManager.getLanguageForPath(editor.document.file._path).getId();

const wrapperId = isEditForm ? "edit-desc-box-wrapper" : "desc-box-wrapper";
const errorId = isEditForm ? "edit-description-length-error" : "description-length-error";

UIHelper.showError(inputId, wrapperId, "Description cannot be more than 80 characters.", errorId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move all UI strings to root/strings.js. The strings are all in English currently and not localized.

// Register cursor activity handler for current and future editors
function registerCursorActivityForEditor(editor) {
if (editor) {
editor.on("cursorActivity", handleCursorActivity);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always good to editor.off and then on to prevent event handler leaks.

devvaannsh added 24 commits July 2, 2025 20:18
devvaannsh added 26 commits July 2, 2025 20:20
Copy link

sonarqubecloud bot commented Jul 2, 2025

@abose abose merged commit 1b63546 into main Jul 3, 2025
16 of 18 checks passed
@abose abose deleted the pluto/snippets branch July 3, 2025 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants